home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / gfx / show / svoUtah22.lha / svoUtahRLE / source / URT / lib / rle_addhist.c < prev    next >
C/C++ Source or Header  |  1991-08-09  |  3KB  |  102 lines

  1. /*
  2.  * This software is copyrighted as noted below.  It may be freely copied,
  3.  * modified, and redistributed, provided that the copyright notice is 
  4.  * preserved on all copies.
  5.  * 
  6.  * There is no warranty or other guarantee of fitness for this software,
  7.  * it is provided solely "as is".  Bug reports or fixes may be sent
  8.  * to the author, who may or may not act on them as he desires.
  9.  *
  10.  * You may not include this software in a program or other software product
  11.  * without supplying the source, or without informing the end-user that the 
  12.  * source is available for no extra charge.
  13.  *
  14.  * If you modify this software, you should include a notice giving the
  15.  * name of the person performing the modification, the date of modification,
  16.  * and the reason for such modification.
  17.  */
  18. /* 
  19.  * rle_addhist.c - Add to the HISTORY comment in header
  20.  * 
  21.  * Author:    Andrew Marriott.
  22.  *         School of Computer Science 
  23.  *         Curtin University of Technology
  24.  * Date:    Mon Sept 10 1988
  25.  * Copyright (c) 1988, Curtin University of Technology
  26.  */
  27.  
  28. #include "rle.h"
  29. #include <stdio.h>
  30. #ifdef USE_STRING_H
  31. #include <string.h>
  32. #else
  33. #include <strings.h>
  34. #endif
  35. #ifdef    SYS_TIME_H
  36. #include <sys/types.h>
  37. #include <sys/time.h>
  38. #else
  39. #include <time.h>
  40. #endif
  41.  
  42. /*****************************************************************
  43.  * TAG( rle_addhist )
  44.  * 
  45.  * Put a history comment into the header struct.
  46.  * Inputs:
  47.  *     argv:        Command line history to add to comments.
  48.  *    in_hdr:        Incoming header struct to use.
  49.  * Outputs:
  50.  *    out_hdr:    Outgoing header struct to add to.
  51.  * Assumptions:
  52.  *     If no incoming struct then value is NULL.
  53.  * Algorithm:
  54.  *     Calculate length of all comment strings, malloc and then set via
  55.  *    rle_putcom.
  56.  */
  57.  
  58. void rle_addhist(argv,in_hdr,out_hdr)
  59. register char    *argv[];
  60. rle_hdr *in_hdr,*out_hdr;
  61. {
  62.     register int    length,i;
  63.     time_t    temp;
  64.     static char    *histoire="HISTORY",                    /* padding must give number of characters in histoire     */
  65.             *padding="\t";                        /*     plus one for "="                    */
  66.     char    *getenv();
  67.     char    *timedate,*old= NULL;
  68.     static char    *newc;
  69.  
  70.     if(getenv("NO_ADD_RLE_HISTORY"))return;
  71.  
  72.     length=0;
  73.     for(i=0;argv[i];i++)
  74.         length+= strlen(argv[i]) +1;                    /* length of each arg plus space. */
  75.  
  76.     (void)time (&temp);
  77.     timedate=ctime(&temp);
  78.     length+= strlen(timedate);                        /* length of date and time in ASCII. */
  79.  
  80.     length+= strlen(padding) + 3 + strlen(histoire) + 1;            /* length of padding, "on "  and length of history name plus "="*/
  81.     if(in_hdr)                                /* if we are interested in the old comments... */
  82.         old=rle_getcom(histoire,in_hdr);                /* get old comment. */
  83.  
  84.     if((old) && (*old)) length+= strlen(old);                /* add length if there. */
  85.  
  86.     length++;                                /*Cater for the null. */
  87.  
  88.     if((newc=(char *)malloc((unsigned int) length)) == NULL)return;
  89.  
  90.     (void)strcpy(newc,histoire);(void)strcat(newc,"=");
  91.     if((old) && (*old)) (void)strcat(newc,old); /* add old string if there. */
  92.     for(i=0;argv[i];i++)
  93.     {
  94.         (void)strcat(newc,argv[i]);(void)strcat(newc," ");
  95.     }
  96.     (void)strcat(newc,"on ");(void)strcat(newc,timedate);            /* \n supplied by time. */
  97.     (void)strcat(newc,padding);                            /* to line up multiple histories.*/
  98.  
  99.     (void)rle_putcom(newc,out_hdr);
  100.  
  101. }
  102.